<?php
/**
 * Created By PhpStorm
 * User: 星洛尘--Stara_Rs
 * Date: 2019/10/15
 * Time: 22:19
 */


namespace app\admin\validate;


use app\lib\exception\ParameterException;
use app\lib\exception\ParametersException;
use think\Request;
use think\Validate;

/**
 * Class BaseValidate
 * 验证类的基类
 */
class BaseValidate extends Validate
{
    /**
     * 检测所有客户端发来的参数是否符合验证类规则
     * 基类定义了很多自定义验证方法
     * 这些自定义验证方法其实，也可以直接调用
     * @throws ParameterException
     * @return true
     */
    public function goCheck()
    {
        //必须设置contetn-type:application/json
        $request = Request::instance();
        $params = $request->param();

        if (!$this->check($params)) {
            $exception = new ParametersException([
                'msg' => is_array($this->error) ? implode(';', $this->error) : $this->error
            ]);
            throw $exception;
        }
        return true;
    }



}